package com.whfc.fuum.service.impl;

import com.whfc.fuum.dao.AppQualificationMapper;
import com.whfc.fuum.entity.AppQualification;
import com.whfc.fuum.service.AppQualificationService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * 资质管理Service实现类
 *
 * @author dzg
 * @since 2025-09-23
 */
@DubboService(interfaceClass = AppQualificationService.class, version = "1.0.0")
public class AppQualificationServiceImpl implements AppQualificationService {

    @Autowired
    private AppQualificationMapper appQualificationMapper;

    @Override
    public AppQualification getById(Integer id) {
        return appQualificationMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AppQualification> list(String qualificationName, Integer unitId) {
        return appQualificationMapper.selectList(qualificationName, unitId);
    }

    @Override
    public boolean save(AppQualification qualification) {
        qualification.setDelFlag(0);
        qualification.setCreateTime(new Date());
        qualification.setUpdateTime(new Date());
        return appQualificationMapper.insert(qualification) > 0;
    }

    @Override
    public boolean update(AppQualification qualification) {
        qualification.setUpdateTime(new Date());
        return appQualificationMapper.updateByPrimaryKey(qualification) > 0;
    }

    @Override
    public boolean delete(Integer id) {
        AppQualification qualification = getById(id);
        if (qualification != null) {
            qualification.setDelFlag(1);
            qualification.setUpdateTime(new Date());
            return update(qualification);
        }
        return false;
    }

    @Override
    public boolean deleteBatch(List<Integer> ids) {
        // 先逻辑删除
        for (Integer id : ids) {
            delete(id);
        }
        // 物理删除可以在后续清理任务中处理
        return true;
    }
}